package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysVideoConvert;
import net.learn.system.convert.SysVideoDetailConvert;
import net.learn.system.convert.SysVideoResultConvert;
import net.learn.system.dao.SysVideoDao;
import net.learn.system.entity.SysVideoDetailEntity;
import net.learn.system.entity.SysVideoEntity;
import net.learn.system.entity.SysVideoResultEntity;
import net.learn.system.query.SysVideoDetailQuery;
import net.learn.system.query.SysVideoQuery;
import net.learn.system.service.SysVideoService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysVideoDetailVO;
import net.learn.system.vo.SysVideoResultVO;
import net.learn.system.vo.SysVideoVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * @author 李立志
 * @since 2022-01-11
 */
@Service
public class SysVideoServiceImpl extends BaseServiceImpl<SysVideoDao, SysVideoEntity> implements SysVideoService {

    @Override
    public Boolean addVideo(SysVideoVO vo){
        SysVideoEntity entity = SysVideoConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        return baseMapper.insert(entity)>0;
    }
    @Override
    public Boolean updateVideo(SysVideoVO vo){
        SysVideoEntity entity = SysVideoConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }
    public List<SysVideoVO> qryVideoList(SysVideoQuery qry) {

        return baseMapper.qryVideoList(qry);
    }
    @Override
    public PageResult<SysVideoVO> qryVideoListPage(SysVideoQuery query) {
        IPage<SysVideoEntity> page = baseMapper.qryVideoListPage(getPage(query), query);

        return new PageResult<>(SysVideoConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
